package taliav3;
import javax.swing.*;

/**
 *
 * @author Ancient
 *
 * Class defining Card:
 * it's variables and methods.
 *
 */
public class Card extends JLabel
{
    /** Varaible punish determines the actual punish of the card.*/
    protected int punish;
    /** Used to specify what Card has been drawned from the cards on player hand.*/
    protected int ind;
    /** Varabiel holding rank of the Card.*/
    protected char rank;
    /** Varabiel holding color of the Card.*/
    protected char color;
    /** Variable holding path to access image file which represents specified card.*/
    protected String pathAwers;
    /** Variable useful to determines wheter the card was joker before when placing card in the Used ArrayList.*/
    protected boolean joker;
    /** Card constructor creating new Card from parameters.*/
    public Card (char rank, char color, int punish, String PathAwers, boolean joker)    
    {
        this.rank = rank;
        this.color = color;
        this.punish = punish;
        this.pathAwers = PathAwers;
        this.ind = 0;
        this.joker=joker;
    }
    /** Card constructor creating new Card object from values of already existing Card object.*/
    public Card (Card card)
    {
        this.rank = card.rank;
        this.color = card.color;
        this.punish = card.punish;
        this.pathAwers = card.pathAwers;
        this.ind = card.ind;
        this.joker = card.joker;
    }
    public Card()   {}
    /** Setting object Card from values of already existing Card object.*/
    public void setCard(Card card)
    {
        this.color = card.color;
        this.rank = card.rank;
        this.punish = card.punish;
        this.pathAwers = card.pathAwers;
        this.ind = card.ind;
        this.joker = card.joker;
    }
    /** Static method returning path (in String) to imagefile of a Card according to set
     * color and rank. Different decks are supported.*/
    protected static String ImagePath(char color, char rank, int talia)
    {
        String path="/taliav3/img/Talie/T0";
        path+=talia+"/";
        if(rank!='B')
        {
            path+=color;
            path+=rank;
            if(rank=='1')
                path+="0";
            path+=".png";
        }
        else
            path+="joker.png";
        return path;
    }
    /** Static method returning punish according to rank and color of Card.*/
    protected static int SetPunish(char rank, int color)
    {
        if(rank=='2' || rank=='3')
            return (int)rank-48;
        else if(rank=='4')
            return -1; // stop!
        else if(rank=='J')
            return 6; // żądanie figury
        else if(rank=='K' && (color=='H' || color=='S'))
            return 5;
        else if(rank=='A')
            return 7; // żądanie koloru
        else
            return 0;
    }
    /** Method converting int rank to char.*/
    protected static char SetRank(int rank)
    {
        switch(rank)
        {
            case 0 : return '2';
            case 1 : return '3';
            case 2 : return '4';
            case 3 : return '5';
            case 4 : return '6';
            case 5 : return '7';
            case 6 : return '8';
            case 7 : return '9';
            case 8 : return '1';
            case 9 : return 'J';
            case 10 : return 'Q';
            case 11 : return 'K';
            case 12 : return 'A';
            case 13 : return 'B';
        }
        return '0';
    }
}
